package me.sdevil507.org.mapper;

import me.sdevil507.org.dto.OrgParamsDto;
import me.sdevil507.org.dto.OrgResultDto;
import me.sdevil507.org.dto.OrgSimpleResultDto;
import me.sdevil507.org.po.OrgPo;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 机构[OrgMapper]
 *
 * @author sdevil507
 * created on 2020-07-13 13:40:20
 */
@Component
@Mapper(componentModel = "spring", nullValuePropertyMappingStrategy = NullValuePropertyMappingStrategy.IGNORE, uses = {OrgKeywordMapper.class, OrgUserRelMapper.class})
public interface OrgMapper {

    /**
     * po => dto
     *
     * @param po 实体类
     * @return dto传输类
     */
    OrgResultDto po2dto(OrgPo po);

    /**
     * pos => dtos
     *
     * @param pos 实体类集合
     * @return dtos传输类集合
     */
    List<OrgResultDto> pos2dtos(List<OrgPo> pos);

    /**
     * po => dto
     *
     * @param po 实体类
     * @return dto传输类
     */
    OrgSimpleResultDto po2SimpleDto(OrgPo po);

    /**
     * pos => dtos
     *
     * @param pos 实体类集合
     * @return dtos传输类集合
     */
    List<OrgSimpleResultDto> pos2SimpleDtos(List<OrgPo> pos);

    /**
     * dto => po
     *
     * @param dto 传输类
     * @return po实体类
     */
    @Mapping(target = "deleted", constant = "false")
    @Mapping(target = "enable", constant = "true")
    OrgPo dto2po(OrgParamsDto dto);

    /**
     * dtos => pos
     *
     * @param dtos 传输类集合
     * @return pos实体类集合
     */
    List<OrgPo> dtos2pos(List<OrgParamsDto> dtos);

    /**
     * 使用dto更新po
     *
     * @param dto 传输类
     * @param po  实体类
     */
    void updatePoFromDto(OrgParamsDto dto, @MappingTarget OrgPo po);
}